1. Field
The present disclosure relates to memory management. More particularly, this invention is directed toward memory address alignment.
2. Description of Related Technology
Presently, many devices are utilizing a processor to carry out some of the functions of the system. Such devices may comprise a general purpose computer, a network processor, a network interface card, and other systems known to a person having ordinary skills in the art. To enable a processor to carry out the function, a memory communicatively coupled with the processor is provided, to hold various data, e.g., instructions executed by the processor, data to be processed, temporary data, and other data.
To support management of the memory, usually a hardware based page allocator (hereinafter free page allocator (FPA)) is provided. The FPA uses a data structure (hereinafter logical stack), e.g., a linked list, heap, containing a series of pointers to free memory. There may be a plurality of logical stacks in an FPA to provide quality of service, virtualization, or other features. A hardware or a software entity receives pointers by requesting a pointer from the FPA. The FPA reads (hereinafter popped) a pointer from one of the plurality of the logical stacks. The pointer points to a base address of a portion of a memory (hereinafter buffer) that the entity can use for some purpose. When the buffer is no longer required, the entity returns a return address pointer (RAP) to the FPA to return to the logical stack, for eventual reuse by another entity. Because of this reuse, a pointer that the FPA returns (hereinafter pushes) to the logical stack (stacked address pointer, (SAP)) must again point to the base address of the buffer so that it may be allocated later to another entity.
As known in the art, according to one method, the RAP is a pointer to the base address of the buffer to be freed. This allows the FPA to push the pointer to the RA directly onto the logical stack, in other words the pointer to the RA is the same as the SAP. The problem with this method is that a returning entity may have only an “opaque pointer” that points to an address somewhere inside a buffer to be freed and not to the beginning of the buffer. Consequently, the entity may not know how to properly compute RA. Furthermore, if the returning entity does know how to compute the pointer to the RA, in a system in which the FPA has a plurality of logical stacks of different sizes, the returning entity may have to keep track of the logical stack from which the pointer was assigned and, consequently to which the pointer has to be returned, and perform the calculation differently for each of the plurality of the logical stacks.
According to another method, the RAP is a pointer to an address somewhere within the buffer to be freed. When such a RAP is returned an entity, i.e., a software layer, may have to keep track of the logical stack from which the pointer was assigned and, consequently to which the pointer has to be returned, and further perform a calculation translating the RAP back to SAP differently for each of the plurality of the logical stacks. Such a method costs instructions, and hardware area may be required to store and send variables keep track of a logical stack between hardware entities until it finally reaches the FPA. Accordingly, there is a need in the art for a method and an apparatus embodying the method, providing a solution to the above identified problems, as well as additional advantages.